#!/usr/bin/env python
"""
	funnybot.py - Loads Configurations, Starts bot and Initializes core.
    Copyright (C) 2012  The FunnyBot Team

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
"""

#import block
from multiprocessing import Process
from framework import *
import config

#activate error handler
error = errors.errors()

#function block
def check_config():
	if not hasattr(config, 'HOST'):
		error.print_err("Oh Noes! HOST is not defined in config.py...")
		error.print_err("Exiting due to fatal error...","ERROR")
		exit()
	if not hasattr(config, 'PORT'):
		error.print_err("Oh Noes! PORT is not defined in config.py...")
		error.print_err("Defaulting to port 6667!","WARNING")
		config.PORT = 6667
	if not hasattr(config, 'SSL'):
		error.print_err("Oh Noes! SSL is not defined in config.py...")
		error.print_err("Defaulting to 'False'","WARNING")
		config.SSL = False
	if not hasattr(config, 'NICK'):
		error.print_err("Oh Noes! NICK is not defined in config.py...")
		error.print_err("Defaulting to 'funnybot'","WARNING")
		config.NICK = "funnybot"
	if not hasattr(config, 'IDENT'):
		error.print_err("Oh Noes! IDENT is not defined in config.py...")
		error.print_err("Defaulting to '%s'" % config.NICK, "WARNING")
		config.IDENT = config.NICK
	if not hasattr(config, 'REALNAME'):
		error.print_err("Oh Noes! REALNAME is not defined in config.py...")
		error.print_err("Defaulting to '%s'" % config.NICK, "WARNING")
		config.REALNAME = config.NICK
	if not hasattr(config, 'CHAN'):
		error.print_err("Oh Noes! CHAN is not defined in config.py...")
		error.print_err("Exiting due to fatal error...", "ERROR")
		exit()
	if not hasattr(config, 'MARKER'):
		error.print_err("Oh Noes! MARKER is not defined in config.py...")
		error.print_err("Defaulting to '\\'", "WARNING")
		config.MARKER = "\\"
	if not hasattr(config, 'LOGIN'):
		error.print_err("Oh Noes! LOGIN is not defined in config.py...")
		error.print_err("Defaulting to 'False'", "WARNING")
		config.LOGIN = False
	if not hasattr(config, 'PASS') and config.LOGIN:
		error.print_err("Oh Noes! PASS is not defined in config.py...")
		error.print_err("Exiting due to fatal error...", "ERROR")
		exit()
	if not hasattr(config, 'LOGGING'):
		error.print_err("Oh Noes! LOGGING is not defined in config.py...")
		error.print_err("Defaulting to 'False'", "WARNING")
		config.LOGGING = False
	if not hasattr(config, 'LOGLEVEL') and config.LOGGING:
		error.print_err("Oh Noes! LOGLEVEL is not defined in config.py...")
		error.print_err("Defaulting to 'ERROR'", "WARNING")
		config.LOGLEVEL = "ERROR"
	if not hasattr(config, 'LOGFILE') and config.LOGGING:
		error.print_err("Oh Noes! PASS is not defined in config.py...")
		error.print_err("Defaulting to 'log.txt'", "WARNING")
		config.LOGFILE = "log.txt"

#main block
#check the configuration
error.print_err("Checking config...")
check_config()
error.print_err("Check complete!, moving on...")

#initialize logging settings
if config.LOGGING:
	error.print_err("Initializing Logging...")
	error.init_log(config.LOGLEVEL,config.LOGFILE)
	error.print_err("Logging is online :)")
else:
	error.print_err("Logging is disabled!")

#initialize queues and interrupts


#initialize core

#load dictionary


#load/refresh modules


#initialize bot


#link interrupts


#link queues


#bring bot online, then sleep :)
